package org.rxc.gift.util;



import org.rxc.gift.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.stereotype.Component;

import javax.mail.internet.MimeMessage;


@Component
public class EmailUtil {
@Autowired
private  JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    private String username;

    public  void send(String title, String text, String to) throws Exception {
        //创建复杂邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        //发送复杂邮件的工具类
        MimeMessageHelper mailMessage = new MimeMessageHelper(mimeMessage,true,"utf-8");

        // 设置发送人
        mailMessage.setFrom(username);
        // 邮件主题
        mailMessage.setSubject(title);
        // 邮件内容
        mailMessage.setText(text);
        // 收件人
        mailMessage.setTo(to);
        javaMailSender.send((MimeMessagePreparator) mailMessage);

    }

}
